<%@page import="com.mvc.config.ApplicationConfig"%>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ include file="/pages/common/header.jsp"%>
<jdf:themeFile file="jquery.jqGrid.css"/>
<jdf:themeFile file="jqGrid/i18n/grid.locale-cn.js" />
<jdf:themeFile file="jqGrid/jquery.jqGrid.src.js" />
<jdf:themeFile file="fileuploader.css" />
<jdf:themeFile file="fileuploader.js" />
<jdf:themeFile file="business/purchase${template}.js" />
</head>
<body>
	<div class="contentBody contentborder">
		<div class="tab-pane" id="tabPane">
			<div id="message">${message}</div>
			<div class="tab-page" id="tabPage1">
				<h1 class="tab">采购管理</h1>
				<div class="contentborder tableForm">
					<jdf:form bean="entity" scope="request">
						<form action="${dynamicDomain}/purchase/save?action=${param.action}" method="post" id="Order">
							<input type="hidden" name="id">
							<input type="hidden" name="objectId">
							<input type="hidden" name="status" id="status">
							<input type="hidden" name="financeStatus" id="financeStatus">
							<input type="hidden" name="purchaseDate">
							<input type="hidden" name="userId">
							<input type="hidden" name="purchaseNo">
                            <input type="hidden" name="auditUserId">
                            <input type="hidden" name="backwardReason">
                            <input type="hidden" name="total">
							<table class="inputTable">
								<c:choose>
									<c:when test="${not empty entity.id }">
										<tr>
											<td class="label cancelBorderLeft">
											     <label for="purchaseNo">采购单编号：</label>
											</td>
											<td class="content" colspan="3">${entity.purchaseNo}</td>
										</tr>
										<tr>
		                                    <td class="label cancelBorderLeft">
		                                        <label for="type">采购单类型：</label>
		                                    </td>
		                                    <td class="content" colspan="3">
		                                         <jdf:dictionaryName dictionaryId="1003" value="${entity.type }"/>
		                                         <input type="hidden" name="type" id="type"/>
		                                         <c:if test="${entity.type==1 }">
										         <input type="hidden" name="companyId">
										         </c:if>
		                                    </td>
		                                </tr>
		                                <tr>
                                            <td class="label cancelBorderLeft">
                                                <label for="type">订单编号：</label>
                                            </td>
                                            <td class="content" colspan="3">
                                                 <input type="hidden" name="orderId">
                                                ${entity.orderNo}
                                            </td>
                                        </tr>
		                                <c:if test="${entity.type==2 }">
		                                <tr id="companyTr">
	                                        <td class="label cancelBorderLeft">
	                                            <label for="companyId">所属公司：</label>
	                                        </td>
	                                        <td class="content" colspan="3">
	                                            <input type="hidden" name="companyId" id="companyId" validate="true">
	                                            <input type="text" id="companyName" value="${entity.company.name}" size="70" readonly="readonly"/>
	                                            <c:if test="${view!=1}">
	                                            <a href="${dynamicDomain}/company/select?ajax=1" class="colorbox">选择公司</a>
	                                            </c:if>
	                                        </td>
	                                    </tr>
		                                </c:if>
									</c:when>
									<c:otherwise>
									<tr>
	                                    <td class="label cancelBorderLeft" style="width: 210px;">
	                                        <label for="type">采购单类型：</label>
	                                    </td>
	                                    <td class="content" colspan="3">
	                                        <select name="type" id="type">
	                                            <jdf:select dictionaryId="1003"/>
	                                        </select>
	                                    </td>
	                                </tr>
	                                <tr id="orderTr">
	                                     <td class="label cancelBorderLeft">
	                                        <label for="orderId">订单：</label>
	                                    </td>
	                                    <td class="content" colspan="3">
	                                        <input type="hidden" name="orderId" id="orderId" validate="true">
	                                        <input type="text" name="orderNo"  id="orderNo" size="70" readonly="readonly"/>
	                                        <a href="${dynamicDomain}/order/selectToPurchase?ajax=1&keepThis=true&TB_iframe=true&height=460&width=700" class="colorbox">选择订单</a>
	                                    </td>
	                                </tr>
	                                <tr id="companyTr" style="display: none">
	                                    <td class="label cancelBorderLeft">
	                                        <label for="companyId">所属公司：</label>
	                                    </td>
	                                    <td class="content" colspan="3">
	                                        <input type="hidden" name="companyId" id="companyId" validate="true">
	                                        <input type="text" id="companyName" value="${entity.company.name}" size="70" readonly="readonly"/>
	                                        <c:if test="${view!=1}">
	                                        <a href="${dynamicDomain}/company/select?ajax=1" class="colorbox">选择公司</a>
	                                        </c:if>
	                                    </td>
	                                </tr>
									</c:otherwise>
								</c:choose>
							    <tr>
									<td class="label cancelBorderLeft">
										<label for="supplierId">供应商：</label>
									</td>
									<td class="content" colspan="3">
										<input type="hidden" name="supplierId" id="supplierId" validate="true">
										<input type="text" id="supplierName" value="${entity.supplier.name}" size="70" readonly="readonly" onkeypress="if(event.keyCode==13) {event.keyCode=9;selectCustomer()}" />
										<a href="${dynamicDomain}/supplier/select?ajax=1&keepThis=true&TB_iframe=true&height=460&width=700" class="colorbox">选择供应商</a>
									</td>
								</tr>
								<tr>
                                    <td class="label cancelBorderLeft">
										<label for="payment">付款方式：</label>
									</td>
									<td class="content" colspan="3">
										<input type="text" name="payment" size="80">
									</td>
                                </tr>
                                <tr>
                                    <td class="label cancelBorderLeft">
                                        <label for="currency">币种：</label>
                                    </td>
                                    <td class="content" colspan="3">
                                        <select name="currency">
                                            <option value=""></option>
                                            <jdf:select dictionaryId="1006"/>
                                        </select>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="label cancelBorderLeft">
                                        <label for="delivaryDate">大货交货时间：</label>
                                    </td>
                                    <td class="content">
                                       <input type="text" id="delivaryDate" size="12" name="delivaryDate" class="Wdate" onClick="WdatePicker({dateFmt:'yyyy-MM-dd',readOnly:true,onpicked:function(dp){setPredictPayDate($dp.$('predictPayDate'), 90);}})">
                                    </td>
                                    <td class="label">
                                        <label for="predictPayDate">预计付款时间：</label>
                                    </td>
                                    <td class="content">
                                       <input type="text" id="predictPayDate" size="12" name="predictPayDate" class="Wdate" onClick="WdatePicker({dateFmt:'yyyy-MM-dd',readOnly:true})">
                                    </td>
                                 </tr>
                                 <tr>
                                     <td class="label cancelBorderLeft">
                                        <label for="delivaryAddress">大货交货地点：</label>
                                    </td>
                                    <td class="content" colspan="3">
                                        <input type="text" name="delivaryAddress" size="70">
                                    </td>
                                </tr>
                                <tr>
                                    <td class="label cancelBorderLeft">
                                        <label for="specification">详细生产规格：</label>
                                    </td>
                                    <td class="content" colspan="3">
                                        <textarea rows="14" cols="55" name="specification"></textarea>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="label cancelBorderLeft">
                                        <label for="quality">质量要求：</label>
                                    </td>
                                    <td class="content"  colspan="3">
                                        <textarea rows="3" cols="55" name="quality"></textarea>
                                    </td>
                                </tr>
								<tr>
									<td class="label cancelBorderLeft">
										<label for="packing">包装：</label>
									</td>
									<td class="content" colspan="3">
										<textarea rows="3" cols="55" name="packing"></textarea>
									</td>
								</tr>
								<tr>
									<td class="label cancelBorderLeft">
										<label for="shipping">出货：</label>
									</td>
									<td class="content" colspan="3">
										<textarea rows="3" cols="55" name="shipping"></textarea>
									</td>
								</tr>
								<tr>
								    <td class="label cancelBorderLeft">
                                        <label for="remark">备注：</label>
                                    </td>
                                    <td class="content" colspan="3">
                                        <textarea rows="5" cols="55" name="remark"></textarea>
                                    </td>
								</tr>
							</table>
						</form>
					</jdf:form>
					<div style="margin: 1px;">
						<table id="orderItemsTable"></table>
						<div id="pager"></div>
					</div>
					<div class="right" style="margin: 2px;width: 100%;">
                       <div id="filelimit-fine-uploader">
                       </div>
                       <c:forEach varStatus="num" var="item" items="${entity.pictures}">
                           <div id="d_f_${item.fileId}" style="float: left;width: 200px;">
                               <a href="${dynamicDomain}/download/${item.fileId}${item.fileSuffix}" class="picture" title="${item.fileName}">
                                   <img alt="${item.fileName}" alt="${item.fileName}" src="${dynamicDomain}/download/${item.fileId}${item.fileSuffix}" width="150">
                               </a>
                               <a href="javascript:deletePicture('${item.fileId}')" style="vertical-align: top;">删除</a>
                           </div>
                       </c:forEach>
                    </div>
					<div class="right" style="margin: 2px;">
						<c:if test="${view!=1 &&(empty entity.status || entity.status == 1)}">
							<button type="button" onclick="$('#status').val(1);$('#Order').submit();" class="submit_button">保存草稿</button>
						</c:if>
						<c:if test="${(view!=1 && (entity.status <20))||param.action=='page'}">
							<button type="button" onclick="$('#status').val(10);$('#Order').submit();" class="submit_button">提交</button>
						</c:if>
						<c:if test="${not empty message}">
						<button type="button" onclick="toUrl('${dynamicDomain}/purchase/create?action=${param.action}')">继续增加</button>
						</c:if>
						<c:choose>
							<c:when test="${param.action=='page'}">
								<button type="button" onclick="toUrl('${dynamicDomain}/purchase/back')">返回</button>
							</c:when>
							<c:otherwise>
								<button type="button" onclick="toUrl('${dynamicDomain}/purchase/${param.action}')">返回</button>
							</c:otherwise>
						</c:choose>
					</div>
				</div>
			</div>
		</div>
	</div>
	<jdf:tableLabelValidate domain="Purchase"/>
	<script type="text/javascript">
	var purchaseId = "${entity.objectId}";
	<c:choose>
	    <c:when test="${(entity.status>=20 && param.action!='page')||view==1}">
	    purchaseEditable = false;
	    </c:when>
	    <c:otherwise>
	    purchaseEditable = true;
	    </c:otherwise>
	</c:choose>
	purchaseFileCount = ${fn:length(entity.pictures)};
	window.onload = createUploader;
    $("#type").bind("change",function(){
        if($(this).val()=="1"){
            $("#orderTr").show();
            $("#companyTr").hide();
                        $("#companyId").val(0);
        }else{
            $("#orderTr").hide();
            $("#orderId").val(0);
            $("#companyId").val("");
            $("#companyTr").show();
        }
     }).change();
	 var units = "";
     <c:forEach varStatus="num" var="item" items="${units}">
     units+="${item.value}:${item.name};";
     </c:forEach>
     units=units.substring(0,units.length-1);
	</script>
	
</body>
</html>